//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.bfsuolcomponents.file.controller;

import com.bfsuolcomponents.file.entity.FileManager;
import com.bfsuolcomponents.file.service.FileManagerService;
import com.bfsuolframework.core.spring.SpringBeanLoader;
import com.bfsuolframework.core.utils.StringUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FileInfo {
    private FileManagerService service = (FileManagerService)SpringBeanLoader.getBean("fileManagerServiceImpl");
    private List<FileInfo.FileInfoNode> nodes = new ArrayList();

    public List<FileInfo.FileInfoNode> getNodes() {
        return this.nodes;
    }

    public void setNodes(List<FileInfo.FileInfoNode> nodes) {
        this.nodes = nodes;
    }

    private FileInfo() {
    }

    public static FileInfo newFileInfo(Long fileId, String fileName) {
        FileInfo fileInfo = new FileInfo();
        return fileInfo.addFileInfo(fileId, fileName);
    }

    public static FileInfo newFileInfo(Long fileId) {
        FileInfo fileInfo = new FileInfo();
        return fileInfo.addFileInfo(fileId);
    }

    public FileInfo addFileInfo(Long fileId, String fileName) {
        if(fileId != null && fileId.longValue() > 0L) {
            if(StringUtils.isBlank(fileName)) {
                FileManager file = (FileManager)this.service.getById(fileId);
                if(file != null) {
                    fileName = file.getFileTitle();
                }
            }

            this.nodes.add(new FileInfo.FileInfoNode(fileId, fileName));
            return this;
        } else {
            return this;
        }
    }

    public FileInfo addFileInfo(Long fileId) {
        return this.addFileInfo(fileId, (String)null);
    }

    public String getFileIds() {
        if(this.nodes != null && this.nodes.size() != 0) {
            StringBuilder builder = null;
            Iterator var3 = this.nodes.iterator();

            while(var3.hasNext()) {
                FileInfo.FileInfoNode node = (FileInfo.FileInfoNode)var3.next();
                if(builder == null) {
                    builder = new StringBuilder();
                    builder.append(node.getFileId());
                } else {
                    builder.append(",").append(node.getFileId());
                }
            }

            return builder.toString();
        } else {
            return "";
        }
    }

    public boolean isHasFiles() {
        return this.nodes != null && this.nodes.size() != 0;
    }

    public String getFileInfos() {
        if(this.nodes != null && this.nodes.size() != 0) {
            StringBuilder builder = null;
            Iterator var3 = this.nodes.iterator();

            while(var3.hasNext()) {
                FileInfo.FileInfoNode node = (FileInfo.FileInfoNode)var3.next();
                if(builder == null) {
                    builder = new StringBuilder("[");
                    builder.append("{'fileId':'").append(node.getFileId()).append("','fileName':'").append(node.getFileName()).append("'}");
                } else {
                    builder.append(",{'fileId':'").append(node.getFileId()).append("','fileName':'").append(node.getFileName()).append("'}");
                }
            }

            return builder.append("]").toString();
        } else {
            return "[]";
        }
    }

    public class FileInfoNode {
        private Long fileId;
        private String fileName;

        public FileInfoNode(Long fileId, String fileName) {
            this.fileId = fileId;
            this.fileName = fileName;
        }

        public Long getFileId() {
            return this.fileId;
        }

        public String getFileName() {
            return this.fileName;
        }
    }
}
